<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Class: ActiveRecord::Errors</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Class</strong></td>
          <td class="class-name-in-header">ActiveRecord::Errors</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../files/vendor/plugins/globalize/lib/globalize/rails/active_record_rb.html">
                vendor/plugins/globalize/lib/globalize/rails/active_record.rb
                </a>
        <br />
            </td>
        </tr>

        <tr class="top-aligned-row">
            <td><strong>Parent:</strong></td>
            <td>
                Object
            </td>
        </tr>
        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
Overrode <a href="Errors.html">Errors</a> methods to handle numbers
correctly for translation, and to automatically translate error messages.
Messages are translated after the field names have been substituted.
</p>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000002">add</a>&nbsp;&nbsp;
      <a href="#M000004">add_on_boundary_breaking</a>&nbsp;&nbsp;
      <a href="#M000003">add_to_base</a>&nbsp;&nbsp;
      <a href="#M000005">on</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">





      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000002" class="method-detail">
        <a name="M000002"></a>

        <div class="method-heading">
          <a href="#M000002" class="method-signature">
          <span class="method-name">add</span><span class="method-args">(attribute, msg = @@default_error_messages[:invalid], num = nil)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Like the regular <a href="Errors.html#M000002">add</a>, but automatically
translates the error message. Takes an extra <tt>num</tt> argument to
support pluralization.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000002-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000002-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/globalize/lib/globalize/rails/active_record.rb, line 10</span>
10:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">add</span>(<span class="ruby-identifier">attribute</span>, <span class="ruby-identifier">msg</span> = <span class="ruby-ivar">@@default_error_messages</span>[<span class="ruby-identifier">:invalid</span>], <span class="ruby-identifier">num</span> = <span class="ruby-keyword kw">nil</span>)
11:       <span class="ruby-ivar">@errors</span>[<span class="ruby-identifier">attribute</span>.<span class="ruby-identifier">to_s</span>] = [] <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@errors</span>[<span class="ruby-identifier">attribute</span>.<span class="ruby-identifier">to_s</span>].<span class="ruby-identifier">nil?</span>
12:       <span class="ruby-ivar">@errors</span>[<span class="ruby-identifier">attribute</span>.<span class="ruby-identifier">to_s</span>] <span class="ruby-operator">&lt;&lt;</span> [ <span class="ruby-identifier">msg</span>, <span class="ruby-identifier">num</span> ]
13:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000004" class="method-detail">
        <a name="M000004"></a>

        <div class="method-heading">
          <a href="#M000004" class="method-signature">
          <span class="method-name">add_on_boundary_breaking</span><span class="method-args">(attributes, range, too_long_msg = @@default_error_messages[:too_long], too_short_msg = @@default_error_messages[:too_short])</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Like the regular <a
href="Errors.html#M000004">add_on_boundary_breaking</a>, but automatically
translates the error message.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000004-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000004-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/globalize/lib/globalize/rails/active_record.rb, line 22</span>
22:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">add_on_boundary_breaking</span>(<span class="ruby-identifier">attributes</span>, <span class="ruby-identifier">range</span>,
23:         <span class="ruby-identifier">too_long_msg</span> = <span class="ruby-ivar">@@default_error_messages</span>[<span class="ruby-identifier">:too_long</span>],
24:         <span class="ruby-identifier">too_short_msg</span> = <span class="ruby-ivar">@@default_error_messages</span>[<span class="ruby-identifier">:too_short</span>])
25:       <span class="ruby-keyword kw">for</span> <span class="ruby-identifier">attr</span> <span class="ruby-keyword kw">in</span> [<span class="ruby-identifier">attributes</span>].<span class="ruby-identifier">flatten</span>
26:         <span class="ruby-identifier">value</span> = <span class="ruby-ivar">@base</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">attr</span>.<span class="ruby-identifier">to_s</span>) <span class="ruby-operator">?</span> <span class="ruby-ivar">@base</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">attr</span>.<span class="ruby-identifier">to_s</span>) <span class="ruby-operator">:</span> <span class="ruby-ivar">@base</span>[<span class="ruby-identifier">attr</span>.<span class="ruby-identifier">to_s</span>]
27:         <span class="ruby-identifier">add</span>(<span class="ruby-identifier">attr</span>, <span class="ruby-identifier">too_short_msg</span>, <span class="ruby-identifier">range</span>.<span class="ruby-identifier">begin</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">value</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">&lt;</span> <span class="ruby-identifier">range</span>.<span class="ruby-identifier">begin</span>
28:         <span class="ruby-identifier">add</span>(<span class="ruby-identifier">attr</span>, <span class="ruby-identifier">too_long_msg</span>, <span class="ruby-identifier">range</span>.<span class="ruby-identifier">end</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">value</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">&gt;</span> <span class="ruby-identifier">range</span>.<span class="ruby-identifier">end</span>
29:       <span class="ruby-keyword kw">end</span>
30:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000003" class="method-detail">
        <a name="M000003"></a>

        <div class="method-heading">
          <a href="#M000003" class="method-signature">
          <span class="method-name">add_to_base</span><span class="method-args">(msg, num = nil)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Like the regular <a href="Errors.html#M000003">add_to_base</a>, but
automatically translates the error message. Takes an extra <tt>num</tt>
argument to support pluralization.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000003-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000003-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/globalize/lib/globalize/rails/active_record.rb, line 17</span>
17:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">add_to_base</span>(<span class="ruby-identifier">msg</span>, <span class="ruby-identifier">num</span> = <span class="ruby-keyword kw">nil</span>)
18:       <span class="ruby-identifier">add</span>(<span class="ruby-identifier">:base</span>, <span class="ruby-identifier">msg</span>, <span class="ruby-identifier">num</span>)
19:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000005" class="method-detail">
        <a name="M000005"></a>

        <div class="method-heading">
          <a href="#M000005" class="method-signature">
          <span class="method-name">on</span><span class="method-args">(attribute)</span>
          </a>
        </div>
      
        <div class="method-description">
          <ul>
<li>Returns nil, if no errors are associated with the specified
<tt>attribute</tt>.

</li>
<li>Returns the error message, if one error is associated with the specified
<tt>attribute</tt>.

</li>
<li>Returns an array of error messages, if more than one error is associated
with the specified <tt>attribute</tt>.

</li>
</ul>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000005-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000005-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/globalize/lib/globalize/rails/active_record.rb, line 55</span>
55:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">on</span>(<span class="ruby-identifier">attribute</span>)
56:       <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@errors</span>[<span class="ruby-identifier">attribute</span>.<span class="ruby-identifier">to_s</span>].<span class="ruby-identifier">nil?</span>
57:         <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span>
58:       <span class="ruby-keyword kw">else</span>
59:         <span class="ruby-identifier">msgs</span> = <span class="ruby-ivar">@errors</span>[<span class="ruby-identifier">attribute</span>.<span class="ruby-identifier">to_s</span>]
60:         <span class="ruby-identifier">txt_msgs</span> = <span class="ruby-identifier">msgs</span>.<span class="ruby-identifier">map</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">msg</span><span class="ruby-operator">|</span> <span class="ruby-identifier">msg</span>.<span class="ruby-identifier">kind_of?</span>(<span class="ruby-constant">Array</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">msg</span>.<span class="ruby-identifier">first</span> <span class="ruby-operator">/</span> <span class="ruby-identifier">msg</span>.<span class="ruby-identifier">last</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">msg</span>.<span class="ruby-identifier">first</span>.<span class="ruby-identifier">t</span> }
61:         <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">txt_msgs</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">==</span> <span class="ruby-value">1</span> <span class="ruby-operator">?</span> <span class="ruby-identifier">txt_msgs</span>.<span class="ruby-identifier">first</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">txt_msgs</span>
62:       <span class="ruby-keyword kw">end</span>
63:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>